package com.atguigu.lease.web.admin.controller.apartment;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.CityInfo;
import com.atguigu.lease.model.entity.DistrictInfo;
import com.atguigu.lease.model.entity.ProvinceInfo;
import com.atguigu.lease.web.admin.service.CityInfoService;
import com.atguigu.lease.web.admin.service.DistrictInfoService;
import com.atguigu.lease.web.admin.service.ProvinceInfoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * ClassName: RegionInfoController
 * Package: com.atguigu.lease.web.admin.controller.apartment
 * Description:
 *
 * @Author ygf
 * @Create 2024/9/14 9:22
 * @Version 1.0
 */
@Tag(name = "地区信息管理接口")
@RestController
@RequestMapping("/admin/region")
public class RegionInfoController {

    @Autowired
    private ProvinceInfoService provinceinfoService;

    @Autowired
    private CityInfoService cityInfoService;


    @Autowired
    private DistrictInfoService districtInfoService;


    @Operation(summary = "查询省份信息列表")
    @GetMapping("province/list")
    public Result<List<ProvinceInfo>> list(){
        //调用service层
        List<ProvinceInfo> provinceInfoList = provinceinfoService.list();
        return Result.ok(provinceInfoList);
    }

    @Operation(summary = "根据省份id查询城市信息列表")
    @GetMapping("/city/listByProvinceId")
    public Result<List<CityInfo>> getCityListByProvinceId(@RequestParam Long id){
        //调用service
        LambdaQueryWrapper<CityInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CityInfo::getProvinceId,id);
        List<CityInfo> cityInfoList = cityInfoService.list(queryWrapper);
        return Result.ok(cityInfoList);
    }

    @Operation(summary = "根据城市id查询区县信息")
    @GetMapping("/district/listByCityId")
    public Result<List<DistrictInfo>> getDistrictListByCityId(@RequestParam Long id){
        //调用service
        //条件
        LambdaQueryWrapper<DistrictInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DistrictInfo::getCityId,id);
        List<DistrictInfo> districtInfoList = districtInfoService.list(queryWrapper);
        return Result.ok(districtInfoList);
    }

}
